package ExperimentTwo.Second_task;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author 北巷_东坡
 * @date 2022/10/16 20:26
 * @computer 10741
 */
public class LoadBalance_LDP206 {
    private static LoadBalance_LDP206 instance = null;
    private ArrayList serverList = null;

    private LoadBalance_LDP206(){
        serverList = new ArrayList<>();
    }

    public static LoadBalance_LDP206 getLoadBalance(){
        if (instance == null) {
            instance = new LoadBalance_LDP206();
        }
        return instance;
    }

    public void addServer(String server){
        serverList.add(server);
    }

    //删除服务器
    public void removeServer(String server) {
        serverList.remove(server);
    }

    //使用Random类随机获取服务器
    public String getServer() {
        Random random = new Random();
        int i = random.nextInt(serverList.size());
        return (String)serverList.get(i);
    }
}
